//
//  CollectionViewCell.m
//
//
//  Created by dllo on 15/11/21.
//  Copyright © 2015年 L-G. All rights reserved.
//

#import "CollectionViewCell.h"
#define HEIGHT  [[UIScreen mainScreen]bounds].size.height / 667
#define WIDTH   [[UIScreen mainScreen]bounds].size.width / 375

@implementation CollectionViewCell
- (void)dealloc
{
    [_label_title release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.label_title = [[UILabel alloc] init];
        self.label_title.layer.masksToBounds = YES;
        self.label_title.textColor = [UIColor grayColor];
        self.label_title.layer.borderWidth = 0.5;
        self.label_title.layer.cornerRadius = 15 * HEIGHT;
        self.label_title.backgroundColor = [UIColor groupTableViewBackgroundColor];
        self.label_title.layer.borderColor = [UIColor grayColor].CGColor;
        self.label_title.textAlignment = NSTextAlignmentCenter;
        self.label_title.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.label_title];
        [_label_title release];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    _hot_word_width = [[self class] heightOfLabel:self.label_title.text andTextFont:[UIFont systemFontOfSize:15] andLabelHeight:30 * HEIGHT];
    self.label_title.frame = CGRectMake(0, 0, _hot_word_width + 20 * HEIGHT, self.frame.size.height);
}
+ (CGFloat)heightOfLabel:(NSString *)text andTextFont:(UIFont *)font andLabelHeight:(CGFloat)height{
    
    CGSize size = CGSizeMake(MAXFLOAT, 30 * HEIGHT);
    NSDictionary *attributeDic = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:attributeDic context:nil];
    return frame.size.width;
}
@end
